import 'package:flutter/material.dart';
import './FooterItem.dart';

class FooterList extends StatefulWidget {
  @override
  FooterListWState createState() => new FooterListWState();
}

class FooterListWState extends State<FooterList> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: const EdgeInsets.fromLTRB(0, 50, 0, 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          FooterItem(name: "设置"),
          FooterItem(name: "菜谱管理"),
          FooterItem(name: "账户"),
          FooterItem(name: "关于我们"),
          FooterItem(name: "查看更新"),
          GestureDetector(
            child: Container(
                margin: const EdgeInsets.fromLTRB(0, 30, 0, 30),
                height: 60,
                decoration: BoxDecoration(
                  color: Colors.white38,
                  boxShadow: [
                    BoxShadow(
                        color: Colors.white,
                        offset: Offset(0.0, 0), //阴影xy轴偏移量
                        blurRadius: 1.0, //阴影模糊程度
                        spreadRadius: 1.0 //阴影扩散程度
                        )
                  ],
                ),
                child: Flex(
                  direction: Axis.horizontal,
                  children: [
                    Expanded(
                        flex: 1,
                        child: Text(
                          "退出登录",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              color: Color.fromRGBO(228, 112, 122, 1),
                              fontSize: 18),
                        ))
                  ],
                )),
            onTap: () => loginout(),
          )
        ],
      ),
    );
  }

  loginout() async {
    bool delete = await showDeleteConfirmDialog1('是否要退出登录？');
    if (delete == null) {
      print("取消");
    } else {
      print("已确认");
    }
  }

  // 弹出对话框
  Future<bool> showDeleteConfirmDialog1(String text) {
    return showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("提示"),
          content: Text(text),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () => Navigator.of(context).pop(), // 关闭对话框
            ),
            FlatButton(
              child: Text("确认"),
              onPressed: () {
                //关闭对话框并返回true
                Navigator.of(context).pop(true);
              },
            ),
          ],
        );
      },
    );
  }
}
